T1 P0
T0 P0

;set temps
M291 S5 J1 F250 L190 H450 R"Set Left Tool Temperature" P"Set temperature of the filament that was last loaded in the Left Tool"
var ll = input

M291 S5 F250 L190 H450 R"Set Right Tool Temperature" P"Set temperature of the filament that was last loaded in the Right Tool"
var rr = input

G10 P0 R{var.ll} S{var.ll}
G10 P1 R{var.rr} S{var.rr}
G10 P2 R{var.ll,var.rr} S{var.ll,var.rr}
G10 P3 R{var.ll,var.rr} S{var.ll,var.rr}



; 1 - Calibrate Z - Offset?
M291 S4 J1 R"Should Z - Offset Calibration be Performed?" P"Make sure Z-Offset was set correctly otherwise you risk damaging your machine" K{"Calibrate Z - Offset","Z - Offset is Correct",}
if input = 0
  M98 P"0:/macros/Z - Offset Calibration" H1
  G10 P0 R{var.ll} S{var.ll}
  G10 P1 R{var.rr} S{var.rr}
  G10 P2 R{var.ll,var.rr} S{var.ll,var.rr}
  G10 P3 R{var.ll,var.rr} S{var.ll,var.rr}



; 2 - Calibrate or Test?
M291 S4 J1 R"Should Tool Height Calibration be Performed?" P" " K{"Yes, Run the Calibration","No, Just Test Tool Height Deviation",}

M98 P"homeall.g" S1

; Calibrate
if input = 0
  
  G90
  M116 P0 S10
  M116 P1 S10
  
  G29 S2
  
  T0
  T1
  T0
  T1
  
  T3
  M83
  G1 E-15 F{60}*{20}

  T0
  
  G90
  G1 X-30 U30 Y-90 Z100 F18000
  
  
  M291 R"Loosen HeatBreak" P"Loosen HeatBreak screw on each hotend to allow HeatBlock to slide. Make sure both nozzles are clean" S3
  
  M913 Z100               ; set motor current
  
  M208 Z-0.2 S1
  G1 Z0  F18000
  G1 Z-3 F18000
  
  
  M291 P" " R"Tighten the HeatBreak screw on each hotend" S2
  G1 Z200 F18000
  M208 Z0 S1
  M913 Z100                ; recover motor current
  M291 R"Fully tighten the HeatBreak screw on each hotend" P"Click ""OK"" when ready. Machine will test offsets on both tools" S2



; 3 - Test Tool Height Deviation Script

T3
M83
G1 E-15 F{60}*{20}

T0

G90
G1 F18000 X0 Y-90 Z3
M208 Z-1 S1


M291 S3 R"Finding Z - Offset" P"Move Z - Axis UP or DOWN with small increments to find a height where you start to feel the resistance of a nozzle when dragging paper" Z1
var lll = move.axes[2].machinePosition

G91
G1 Z20.5
G90
G1 F18000 X-999 U0 Y-90
G91
G1 Z-20
G90


M291 S3 R"Finding Z - Offset" P"Move Z - Axis UP or DOWN with small increments to find a height where you start to feel the resistance of a nozzle when dragging paper" Z1
var rrr = move.axes[2].machinePosition

M208 Z0 S1

var ddd = {var.lll} - {var.rrr}

G10 P0 S0 R0
G10 P1 S0 R0
G10 P2 S0 R0
G10 P3 S0 R0

G90
G1 F18000 X-999 U999 Y150 Z100

if abs(var.ddd) <= 0.07
  M291 R{"Calibration Success, deviation is "^var.ddd^" mm"} P" " S2
else
  M291 R"Calibration was not successful" P{"Deviation of "^abs(var.ddd)^" mm is too high. Click ""OK"" to repeat the procedure"} S3
  M98 P"0:/macros/System/Calibration/Tool Alignment/Auto Tool Height Calibration)"